﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hp.Vertica.Client.Internal
{
    public abstract class VerticaDataTypeWithScale : VerticaDataTypeWithPrecision
    {
        public VerticaDataTypeWithScale() { }

        public VerticaDataTypeWithScale(Int32 precision, Int32 scale)
            : base(precision)
        {
            this.Scale = scale;
        }

        public override int Precision
        {
            get
            {
                return base.Precision;
            }
            set
            {
                base.Precision = value;
                //reset scale in case Precision has been reset and less than scale
                this.Scale = this.Scale;
            }
        }
        public override int Scale
        {
            get
            {
                return base.Scale;
            }
            set
            {
                base.Scale = value < this.MinPrecision ? this.MinPrecision : (value > this.Precision ? this.Precision : value);
            }
        }

        public override string ToString()
        {
            return this.Name + "(" + this.Precision + "," + this.Scale + ")";
        }
    }
}
